/* Created by Aquariuslt on 5/20/17.*/


DeliveringOrdersController.$inject = ['ordersService','$scope','$location'];
function DeliveringOrdersController(ordersService,$scope,$location) {
   var $ = require('jquery');
    $('#nav').show();
  var vm = $scope.vm = {};
  vm.orderlist = [];
  vm.merchant = JSON.parse(sessionStorage.merchant); //前端session维持的session

  ordersService.deliveringOrderlist(vm.merchant.icnum,function(err,orderlist){
        vm.orderlist = orderlist;
  });

  vm.receiveOrder = function(order){
    for(let i = 0;i < vm.orderlist.length;i++){   //改变前端数据的状态
      if(order._id === vm.orderlist[i]._id){
        vm.orderlist[i].ostate = "1";
        break;
      }
    }
    ordersService.receiveOrder(order,function(err,data){
      //回调函数里什么都不做
    })
  }

    vm.refuseOrder = function(order){
    for(let i = 0;i < vm.orderlist.length;i++){   //改变前端数据的状态
      if(order._id === vm.orderlist[i]._id){
        vm.orderlist[i].ostate = "2";
        break;
      }
    }
    ordersService.refuseOrder(order,function(err,data){
      //回调函数里什么都不做
    })
  }

    vm.deliverOrder = function(order){
    for(let i = 0;i < vm.orderlist.length;i++){   //改变前端数据的状态
      if(order._id === vm.orderlist[i]._id){
        vm.orderlist[i].ostate = "3";
        break;
      }
    }
    ordersService.deliverOrder(order,function(err,data){
      //回调函数里什么都不做
    })
  }  


}

module.exports = DeliveringOrdersController;